package com.reider.log4AS3.dataholder
{
	import com.reider.log4AS3.dataholder.Level;
	import com.reider.log4AS3.utils.ObjectContainer;
	
	import flash.utils.getQualifiedClassName;
	
	/**
	 * This class stores all the available levels and can be used to add custom ones.
	 */
	
	public class LevelHolder
	{
		public static const ALL:Level 		= new Level(int.MIN_VALUE, "ALL");
		public static const DEBUG:Level 	= new Level(100, "DEBUG");
		public static const INFO:Level 		= new Level(200, "INFO");
		public static const WARN:Level 		= new Level(300, "WARN");
		public static const ERROR:Level 	= new Level(400, "ERROR");
		public static const FATAL:Level 	= new Level(500, "FATAL");
		public static const OFF:Level 		= new Level(int.MAX_VALUE, "OFF");
		
		private static var initialized:Boolean = init();
		private static var levels:ObjectContainer
		
		
		/**
		 * Adds a custom level
		 * 
		 * @param level The Level instance to be added
		 */
		public static function addLevel(level:Level):void
		{
			if(!(level is Level)){
				trace("level can't be added, must be:", getQualifiedClassName( Level ))
				return
			}
			levels.add(level.name.toUpperCase(), level)
		}
		
		/**
		 * Returns a level by its name
		 * 
		 * @param name The name of the level
		 * @return The lavel given by the name parameter
		 */
		
		public static function getLevel(name:String):Level
		{
			return Level(levels.getObj(name.toUpperCase()))
		}
		
		private static function init():Boolean
		{
			levels = new ObjectContainer()
			
			addLevel(ALL)
			addLevel(DEBUG)
			addLevel(INFO)
			addLevel(WARN)
			addLevel(ERROR)
			addLevel(FATAL)
			addLevel(OFF)
			
			return true;	
		}
	}
}